package com.guqj.basis.reflect;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.ArrayList;

public class ReflectInstance {

	public static void main(String[] args) throws IllegalAccessException, IllegalArgumentException,
			InvocationTargetException, NoSuchMethodException, SecurityException {
		ArrayList<Integer> list = new ArrayList<>();
		Method method = list.getClass().getMethod("add", Object.class);
		method.invoke(list, "abc");
		method.invoke(list, "Java反射机制实例。");
		System.out.println(list.get(1));
		
		System.out.println(ReflectInstance.class.getClassLoader().getParent().getParent()); // Bootstrap ClassLoader 负责加载$JAVA_HOME中jre/lib/rt.jar里所有的class，由C++实现，不是ClassLoader子类
		System.out.println(ReflectInstance.class.getClassLoader().getParent()); // Extension ClassLoader 负责加载java平台中扩展功能的一些jar包，包括$JAVA_HOME中jre/lib/*.jar或-Djava.ext.dirs指定目录下的jar包
		System.out.println(ReflectInstance.class.getClassLoader()); // App ClassLoader 负责加载classpath中指定的jar包及目录中class
	}
}
